package com.itheima.controller;

import com.itheima.utils.Result;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class CookieController {
    @GetMapping("/setCookie")
    public Result setCookie(HttpServletResponse response){
        String name = "kunkun";
        String value = "jinitaimei";
        Cookie cookie = new Cookie(name,value);
        response.addCookie(cookie);
        return Result.success();
    }

    @GetMapping("/getCookie")
    public Result setCookie(HttpServletRequest request){
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            log.info("name:{},value:{}",cookie.getName(),cookie.getValue());
        }
        return Result.success();
    }
}
